home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / os2 / cenv2_19.arj / PRIMES.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-08  |  812b  |  23 lines

  1. EXTPROC CEnvi
  2. /****************************************************************************
  3.  *** Primes.cmd  Print out prime numbers until a key is pressed or we run ***
  4.  *** ver.1       out of memory or overflow                                ***
  5.  ****************************************************************************/
  6.  
  7. printf("Printing prime numbers until a key pressed (or failure):\n")
  8.  
  9. for ( Count = 0, Try = 2; !kbhit(); Try++ ) {
  10.    // check if this is divisible by any of the primes found so far
  11.    for ( i = 0; i < Count; i++ )
  12.       if !(Try % Prime[i])
  13.          break
  14.    if ( i == Count )
  15.       // this new prime number was found, and so add to the list and print it
  16.       printf("%d\t",Prime[Count++]=Try)
  17. }
  18. // flush the keyboard
  19. while( kbhit() ) getch()
  20.  
  21. printf("\n")
  22.  
  23.